public class SaveAccount {
    // static变量年利率
    private static double Rate;

    // 存款余额
    private double saving;

    // 默认构造方法
    protected SaveAccount() {
        saving = 0.0;
    }

    protected SaveAccount(double saving) {
        this.saving = saving;
    }

    // 返回存款余额
    public double getSaving() {
        return saving;
    }

    // caculate方法计算月息
    public double caculate() {
        double monthMoney = saving * Rate / 12;
        this.saving += monthMoney;
        return monthMoney;
    }

    // ModifyRate方法设置Rate
    public static void ModifyRate(double newRate) {
        SaveAccount.Rate = newRate;
    }

    // main方法进行测试
    public static void main(String[] args) {
        // 首先实例化两个saver对象
        SaveAccount saver1 = new SaveAccount(2000.00);
        SaveAccount saver2 = new SaveAccount(3000.00);

        // 设置Rate
        SaveAccount.ModifyRate(0.04);

        // 计算月息并加入saving
        saver1.caculate();
        saver2.caculate();

        // 打印两个储户的存款
        System.out.println(saver1.getSaving());
        System.out.println(saver2.getSaving());
    }
}